# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>
# Contributor: Andrew Sun <adsun701@gmail.com>

_realname=libcerf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.5
pkgrel=2
pkgdesc="Complex error functions, Dawson, Faddeeva, and Voigt function (mingw-w64)"
arch=('any')
url='http://apps.jcns.fz-juelich.de/doku/sc/libcerf'
license=('MIT')
source=("http://apps.jcns.fz-juelich.de/src/${_realname}/${_realname}-${pkgver}.tgz"
        "0001-libcerf-1.5-fix-shared-lib.patch")
sha256sums=('e36dc147e7fff81143074a21550c259b5aac1b99fc314fc0ae33294231ca5c86'
            '9e76eb52ad0af076e948792a5cf4b04a407f43e2a4e7203b7412bdac1136ac97')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-libcerf-1.5-fix-shared-lib.patch"
  autoreconf -fiv
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared 

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
